const {inquireOfCityData, allCityInfo} = require('../models/all_sales')
const zlib = require('zlib')
const getAllCityInfoHandler = async (req, res) => {
    let data = await allCityInfo()

// 使用deflate压缩数据
    zlib.deflate(JSON.stringify(data), (err, buffer) => {
        if (!err) {
            res.send({
                meta: {
                    state: 200,
                    msg: '查询成功'
                },
                data:buffer.toString('base64')// 以base64压缩
            })
        }
    })
}

const getCityDataHandler = async (req, res) => {
    let {city, pageSize, pageNo} = req.body
    let data = await inquireOfCityData(city, pageSize, pageNo)
    res.send({
        meta: {
            state: 200,
            msg: '查询成功'
        },
        data: data
    })
}

module.exports = {
    getCityDataHandler,
    getAllCityInfoHandler
}
